class StaffingExpertController < ApplicationController

  def home
    require 'net/http'
    source = 'http://140.211.68.130/GetAllPositionTypes'
    resp = Net::HTTP.get_response(URI.parse(source))
    data = resp.body
    result = JSON.parse(data)

    @full = result['positions']

  end #end home

  def questions
    @position_type_id = ''
    posID = params[:id]

    params.each do |key,value|
      if key.to_s == 'id'
        @position_type_id = value
      end #end if
    end #end loop

    require 'net/http'
    source = URI.parse('http://140.211.68.130/GetQuestions')
    resp = Net::HTTP.post_form(source, 'position_type_id' => @position_type_id.to_s)
    data = resp.body.to_s

    begin
      result = JSON.parse(data)
      @full = result['questions']
    rescue JSON::ParserError => e
      # It's not valid json, show error GTFO..
      puts e.message
      puts e.backtrace
      return
    end

  end #end questions

  def update_question
    @k = ''
    @v = ''
    params.each do |key,value|
      if(key == 'position_question_id' || key == 'position_type_id')
        @k = key
        @v = value
      end
    end

  end #end update

  private
  def get_questions
    require 'net/http'
    source = URI.parse('http://140.211.68.130/GetQuestions')
    resp = Net::HTTP.post_form(source, 'position_type_id' => @position_type_id.to_s)
    data = resp.body.to_s

    begin
      @result = JSON.parse(data)
    rescue JSON::ParserError => e
      # It's not a valid json.
      puts e.message
      puts e.backtrace
      return
    end #end of begin

  end #end get_questions

end
